package com.ad.pet.app.main.concer;

import android.app.Activity;

import com.ad.pet.api.ApiService;
import com.ad.pet.app.RxDisposable;
import com.ad.pet.common.data.http.AppSubscriber;
import com.ad.pet.common.data.injector.PerActivity;
import com.ad.pet.common.structure.mvp.AbsBasePresenter;
import com.ad.pet.models.remote.main.PetConcer;

import java.util.List;

import javax.inject.Inject;

/**
 * Created by liuyixiang on 2019/11/30.
 */
@PerActivity
public class PetConcerPresenter  extends AbsBasePresenter implements PetConcerContract.Presenter{

    private ApiService mApiService;
    private PetConcerContract.View mView;

    private Activity mActivity;

    private RxDisposable mRxDisposable;

    @Inject
    public PetConcerPresenter(ApiService apiService,
                                Activity activity, RxDisposable rxDisposable) {
        mApiService = apiService;
        mActivity = activity;
        mRxDisposable = rxDisposable;
    }

    @Override
    public void onCreate(PetConcerContract.View view) {
        this.mView = view;
    }

    @Override
    public void onDestroy() {
        if (mRxDisposable != null)
            mRxDisposable.clear();
        if (mActivity != null) mActivity = null;
        mView = null;
    }

    @Override
    public void getPetConcers(String longTitu,String latitude,String page,String search,String provice_id) {
        mRxDisposable.add(mApiService.getPetConcers( longTitu, latitude, page, search, provice_id)
                .subscribe(new AppSubscriber<List<PetConcer>>(mView) {
                    @Override
                    public void next(List<PetConcer> list) {

                        mView.getPetConcersSuccess(list);
                    }
                }));
    }
}
